package com.kingsoft.miot.bridge.controller;

import com.alibaba.fastjson.JSONObject;
import com.kingsoft.miot.bridge.common.CommonResult;
import com.kingsoft.miot.bridge.pojo.log.LogBean;
import com.kingsoft.miot.bridge.pojo.log.LogData;
import com.kingsoft.miot.bridge.utils.Paging;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * zhangybt
 */
@RestController
public class LogController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LogController.class);

    /**
     * 房间管理-房间详情-获取房间日志
     * 请求方式：POST
     *
     * @return
     */
    @RequestMapping(value = "/data/hotels/{id}/houses/{house_id}/logs",
            produces = {"application/json;charset=UTF-8"}, method = RequestMethod.POST)
    public CompletableFuture<String> findLogs(@RequestBody JSONObject params, @PathVariable int id, @PathVariable int house_id) {
        LOGGER.info("房间管理-房间详情-获取房间日志->" + params + id + house_id);
        JSONObject resultJson = new JSONObject();
        resultJson.put("total_pages", 7);
        resultJson.put("total_count", 50);
        resultJson.put("current_page", 1);
        resultJson.put("size", 3);
        Calendar calendar = Calendar.getInstance();
        LogData logData = new LogData();
        logData.setTime(calendar.getTimeInMillis());
        List info1 = new ArrayList();
        info1.add("睡眠模式启动成功");
        logData.setInfo(info1);

        LogData logData1 = new LogData();
        logData1.setTime(calendar.getTimeInMillis());
        List info2 = new ArrayList();
        info2.add("门厅吸顶灯");
        info2.add("客厅吸顶灯");
        info2.add("阳台吸顶灯");
        logData1.setInfo(info2);

        LogBean logBean = new LogBean();
        List<LogData> logDataList = new ArrayList<>();
        logDataList.add(logData);
        logDataList.add(logData1);
        logBean.setTime(new Date());
        logBean.setData(logDataList);

        resultJson.put("list", logBean);
        return CompletableFuture.supplyAsync(() -> {
            return CommonResult.jsonString(resultJson);
        });
    }
}
